#include "GameStateManager.h"

void GameStateManager::ChangeState(GameState* new_state)
{
    GameState* current_state = PopCurrentState();
    current_state->Cleanup();
    
    _active_states.push(new_state);
    new_state->Init();
}

void GameStateManager::PushState(GameState* new_state)
{
    GetCurrentState()->Pause();
    
    _active_states.push(new_state);
    new_state->Init();
}

void GameStateManager::PopState()
{
    GameState* current_state = PopCurrentState();
    current_state->Cleanup();
    
    GameState* new_current_state = _active_states.top();
    new_current_state->Resume();
}

void GameStateManager::Update()
{
    GetCurrentState()->Update();
}

void GameStateManager::Render(SDL_Surface* surface)
{
    GetCurrentState()->Render(surface);
}

GameState* GameStateManager::GetCurrentState()
{
    return _active_states.top();
}

GameState* GameStateManager::PopCurrentState()
{
    GameState* current_state = GetCurrentState();
    _active_states.pop();
    return current_state;
}

